<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="props.formOperate !=='view'?['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']:[]"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('xCorpbank.quick Search Fields') })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupForm v-if="baTable.form.operate"/>
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted } from 'vue'
import baTableClass from '/@/utils/baTable'
import { xCorpbank } from '/@/api/controllerUrls'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import { useRoute } from 'vue-router'

const { t } = useI18n()

const props = defineProps({
    companyName:String,
    companyName_full:String,
    formOperate:String
})
const tableRef = ref()
const optButtons = defaultOptButtons(["edit","delete"])
const baTable = new baTableClass(
    new baTableApi(xCorpbank),
    {
        pk: 'ID',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('xCorpbank.CORP'), prop: 'CORP', align: 'center' },
            { label: t('xCorpbank.CORPNAME'), prop: 'CORPNAME', align: 'center' },
            { label: t('xCorpbank.ADDR'), prop: 'ADDR', align: 'center',show:false },
            { label: t('xCorpbank.TEL'), prop: 'TEL', align: 'center',show:false },
            { label: t('xCorpbank.BANKNAME'), prop: 'BANKNAME', align: 'center' },
            { label: t('xCorpbank.BANKACCOUNT'), prop: 'BANKACCOUNT', align: 'center' },
            { label: t('xCorpbank.MONEYTYPE'), prop: 'MONEYTYPE', align: 'center' },
            { label: t('xCorpbank.REMARK'), prop: 'REMARK', align: 'center' ,show:false, operator: false},
            { label: t('xCorpbank.ZZSFLAG'), prop: 'ZZSFLAG', align: 'center' },
            { label: t('xCorpbank.OP'), prop: 'OP', align: 'center',show:false, operator: false },
            { label: t('xCorpbank.OPTIME'), prop: 'OPTIME', align: 'center', render: 'datetime', sortable: 'custom', operator: false, width: 160 ,show:false},
            { label: t('operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false,show:props.formOperate !=='view' },
        ],
        dblClickNotEditColumn: [undefined, ],
        defaultOrder: { prop: 'CORP', order: 'desc' },
    },
    {
        defaultItems: [],
    }
)

provide('baTable', baTable)

const route = useRoute()
const type = route.name === 'corplib/customer'? 1:2

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.table.filter!.type = type
    baTable.table.filter!.CORP = props.companyName
    // baTable.comSearch.form.CORP = props.companyName

    if(props.formOperate!=='add'){
        baTable.getIndex()?.then(() => {
            baTable.initSort()
            baTable.dragSort()
        })
    }
})
</script>

<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
    name: 'xCorpbank',
})
</script>

<style scoped lang="scss"></style>
